Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Secret/secretmanager.aws custom diff logic when replica config is empty #1144

Conversation

erhancagirici
Copy link
Collaborator

Description of your changes

Fixes the custom diff logic (introduced at #1107) for replica attribute when it is not specified in the config and the diff does not involve replica field. The custom diff function is triggered for any update diff, and the current logic tries to read the replica field unconditionally. When replica is not specified in config, the get operation fails the whole custom diff function, therefore the Observe operation.

This change fixes the custom diff logic by:

  • early exit with no error when there is no change/diff involved for replica. We only need to change
  • early exit with no error if replica attibute is not specified in the MR spec. This is already handled properly by the regular diff and needs no customization.

Fixes #1128

I have:

  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Tested with the spec at #1128

@mbbush
Copy link
Collaborator

mbbush commented Feb 13, 2024

/test-examples="examples/secretsmanager/v1beta1/secret.yaml"

@mbbush
Copy link
Collaborator

mbbush commented Feb 13, 2024

@erhancagirici this looks like a good fix, but in the interest of improving our test coverage, I'm puzzled why uptest doesn't fail on main without this fix.

When I tried to reproduce the issue, I got the error described in #1128 when I was observing an existing secret, by setting the external name annotation, but not when I just created a new secret. It seems like that should be caught by the import step in uptest, yet that passes consistently for me.

Any ideas why?

@mbbush
Copy link
Collaborator

mbbush commented Feb 14, 2024

It looks like the key difference in reproducing this bug is that when I duplicated the existing resource, I changed its metadata.name, which changed one of the crossplane-managed tags, which created a non-nil diff.

This makes me want to get Update tests actually running in uptest for provider-aws.

Copy link
Collaborator

@mbbush mbbush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the bug using uptest, and opened #1154 with examples that fail on main, but pass on this branch.

I'd be happy for you to just cherry-pick/copy in that commit to your branch, or merge my PR and rebase, or whatever other git workflow you find easiest.

@@ -35,13 +35,25 @@ func Configure(p *config.Provider) { //nolint:gocyclo
return diff, nil
}

resData, err := schema.InternalMap(r.TerraformResource.SchemaMap()).Data(state, diff)
if err != nil {
return nil, errors.New("could not construct resource data")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really something we want to fail the whole observe loop for? I don't fully understand when this could happen, so I don't know how bad it is.

Copy link
Collaborator Author

@erhancagirici erhancagirici Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

under "normal" operation this should never return an error. An error here indicates an issue with the resource schema or the produced state. More specifically, this is a very fundamental statement and the same line is also run by the terraform SDK library already in earlier stages of observe, so any error should be already emitted if any before visiting the custom diff function.So, IMHO it is OK to fail the whole observe here

@erhancagirici erhancagirici marked this pull request as ready for review February 15, 2024 08:29
@erhancagirici
Copy link
Collaborator Author

I was able to reproduce the bug using uptest, and opened #1154 with examples that fail on main, but pass on this branch.

I'd be happy for you to just cherry-pick/copy in that commit to your branch, or merge my PR and rebase, or whatever other git workflow you find easiest.

Many thanks 🎉
As you have already discovered, this bug is reproducible when

  • a non-nil Update diff occurs (non-create, non-destroy)
  • replica is not specified in resource config

I was also just about to send a very similar example change, and for the sake of completeness of this PR, I will cherrypick your commit here. Thanks again for the valuable contribution!

@erhancagirici
Copy link
Collaborator Author

/test-examples="examples/secretsmanager/v1beta1/secret.yaml"

@erhancagirici
Copy link
Collaborator Author

/test-examples="examples/secretsmanager/v1beta1/secret-withreplica.yaml"

Copy link
Collaborator

@sergenyalcin sergenyalcin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @erhancagirici LGTM!

@erhancagirici erhancagirici merged commit 81d43d0 into crossplane-contrib:main Feb 15, 2024
10 of 11 checks passed
@erhancagirici erhancagirici deleted the secret-secretmanager-customdiff-fix branch February 15, 2024 10:33
Copy link

Backport failed for release-0.47, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git fetch origin release-0.47
git worktree add -d .worktree/backport-1144-to-release-0.47 origin/release-0.47
cd .worktree/backport-1144-to-release-0.47
git checkout -b backport-1144-to-release-0.47
ancref=$(git merge-base 105ce93b8e3b103e5757e2cd9a1394a6e55a22f5 3df0d8de85c8beb87fcec918013f96c9fd088c97)
git cherry-pick -x $ancref..3df0d8de85c8beb87fcec918013f96c9fd088c97

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Secret never Sync
4 participants